//
//  SecViewController.m
//  CookGuest
//
//  Created by LiuYanJun on 15/9/18.
//  Copyright (c) 2015年 杨元石. All rights reserved.
//

#import "SecViewController.h"

#define WIDTH ([UIScreen mainScreen].applicationFrame.size.width)
#define HEIGHT ([UIScreen mainScreen].applicationFrame.size.height)
#import "Menu.h"
#import "Know.h"
#import "MineList_SecViewController.h"




@interface SecViewController ()<menuViewDelegate,knowListDelegate>


@property (nonatomic, retain) UISegmentedControl *segment;
@property (nonatomic, retain) UIView *titleView;
@property (nonatomic, retain) Menu *menuView;
@property (nonatomic, retain) Know *knowView;



@end

@implementation SecViewController

-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}

-(void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:233./255. green:243./255. blue:225./255. alpha:1.];
    [self seg];
    
    // Do any additional setup after loading the view.
}



-(void)seg
{
    NSArray *array = @[@"菜谱收藏",@"常识宝典"];
    self.segment = [[UISegmentedControl alloc]initWithItems:array];
    self.segment.tintColor = [UIColor whiteColor];
    self.segment.frame = CGRectMake(0, 0, WIDTH * 0.4, 30);
    [self.segment addTarget:self action:@selector(segmentClick:) forControlEvents:UIControlEventValueChanged];
    [self.navigationController.navigationBar addSubview:self.segment];
    self.segment.selectedSegmentIndex = 0;
    
    
    
    
    UIButton * leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 30, 20);
    [leftButton addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"backk.png"] forState:UIControlStateNormal];
    UIBarButtonItem * custom = [[UIBarButtonItem alloc]initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = custom;
    
    
    //UIView
    
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(WIDTH * 0.3, 0, WIDTH * 0.4, 30)];
    self.navigationItem.titleView = titleView;
    [titleView addSubview:self.segment];
    
    
    
    self.menuView = [[Menu alloc]initWithFrame:self.view.frame];
    [self.view addSubview:self.menuView];
    self.menuView.delegate = self;
    
    
    
    self.knowView = [[Know alloc]initWithFrame:self.view.frame];
    [self.view addSubview:self.knowView];
    self.knowView.delegate = self;
    self.knowView.hidden = YES;
    
}



-(void)segmentClick:(UISegmentedControl *)seg
{
    switch (seg.selectedSegmentIndex) {
        case 0:
            self.menuView.hidden = NO;
            self.knowView.hidden = YES;
            
            break;
        case 1:
            self.menuView.hidden = YES;
            self.knowView.hidden = NO;
            
        default:
            break;
    }
}




#pragma mark-协议PUSH
-(void)pushViewController:(MineList_SecViewController *)viewController
{
    
    [self.navigationController pushViewController:viewController animated:YES];
    
}

-(void)pushController:(KnowList_SecViewController *)controller
{
    [self.navigationController pushViewController:controller animated:YES];
}




-(void)leftClick
{
    [self.navigationController popViewControllerAnimated:YES];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
